import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:person_model_project/adapter/main_coach_adapter.dart';
import 'package:person_model_project/adapter/main_toppic_adapter.dart';

/**
 *
 * @ProjectName:    person_model_project
 * @ClassName:      main_body
 * @Description:    dart类作用描述
 * @Author:         孙浩
 * @QQ:             243280864
 * @CreateDate:     2021/1/31 10:34 PM
 */
class MainBodyPage extends StatefulWidget {
  @override
  _MainBodyPageState createState() => _MainBodyPageState();
}

class _MainBodyPageState extends State<MainBodyPage> {
  @override
  Widget build(BuildContext context) {
    return EasyRefresh.custom(slivers: [
      SliverToBoxAdapter(
        child: buildBanner(),
      ),
      buildDivider(),
      SliverToBoxAdapter(
        child: buildTitle("Coach_教练"),
      ),
      buildDivider(height: 10.w),
      SliverPadding(padding: EdgeInsets.symmetric(horizontal: 40.w),sliver: SliverGrid(
          delegate: SliverChildBuilderDelegate(
                  (ctx, index) => MainCoachAdapter(index, ""),childCount: 4),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2, crossAxisSpacing: 20.w, mainAxisSpacing: 20.w)),),
      buildDivider(),
      SliverToBoxAdapter(
        child: buildTitle("Topic_专题"),
      ),
      buildDivider(height: 10.w),
      SliverList(
        delegate: SliverChildBuilderDelegate(
                (ctx, index) => MainTopicAdapter(index, ""),childCount: 4),

      ),
      SliverToBoxAdapter(
        child: buildTitle("Strategy_攻略"),
      ),
      buildDivider(height: 10.w),
    ]);
  }

  SliverToBoxAdapter buildDivider({double height}) => SliverToBoxAdapter(
        child: SizedBox(
          height: height ?? 24.w,
        ),
      );

  buildBanner() => AspectRatio(
        aspectRatio: 5 / 3,
        child: Swiper(
          itemCount: 3,
          itemBuilder: (ctx, index) {
            return Container(
              margin: EdgeInsets.symmetric(horizontal: 44.w),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(24.w),
                  boxShadow: [
                    BoxShadow(color: Colors.black12, blurRadius: 10.w)
                  ]),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(24.w),
                child: ConstrainedBox(
                  constraints: BoxConstraints.expand(),
                  child: Image.network(
                    "http://via.placeholder.com/350x150",
                    fit: BoxFit.cover,
                  ),
                ),
              ),
            );
          },
          autoplay: true,
        ),
      );

  buildTitle(String name) => Container(
        margin: EdgeInsets.symmetric(horizontal: 44.w),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  name,
                  style:
                      TextStyle(fontSize: 32.sp, fontWeight: FontWeight.bold),
                ),
                Icon(
                  Icons.arrow_forward_ios,
                  size: 28.w,
                  color: Colors.grey,
                ),
              ],
            )
          ],
        ),
      );
}
